<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微博登录</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-image: url('./gd.jpg'); /* 替换为实际背景图片URL */
            background-size: cover;
            background-position: center;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .login-container {
            background-color: rgba(255, 255, 255, 0.8); /* 半透明背景 */
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            width: 300px;
            text-align: center;
        }

        h1 {
            margin-bottom: 20px;
            color: #333;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
            text-indent: 30px; /* 内容缩进 */
        }

        input[type="text"] {
            background: url('https://example.com/user-icon.png') no-repeat 10px center; /* 用户图标 */
            background-size: 20px;
        }

        input[type="password"] {
            background: url('https://example.com/password-icon.png') no-repeat 10px center; /* 密码图标 */
            background-size: 20px;
        }

        input[type="button"] {
            width: 100%;
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        input[type="button"]:hover {
            background-color: #45a049;
        }

        .links {
            margin-top: 15px;
            text-align: left;
        }

        .links a {
            color: #4CAF50;
            text-decoration: none;
            margin-right: 10px;
        }

        .links a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>

<div class="login-container">
    <h1>登录页面</h1>
    <form>
        <input type="text" placeholder="用户名" v-model="user.username">
        <input type="password" placeholder="密码" v-model="user.password">
        <input type="button" value="登录" @click="login()">
    </form>
    <div class="links">
        <a href="#">忘记密码</a>
        <a href="#">注册新账号</a>
    </div>
</div>

<!-- 引入axios和vue的框架文件 -->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el: ".login-container",
        data: {
            user: {
                username: "",
                password: ""
            }
        },
        methods: {
            login() {
                axios.post("/v1/users/login", v.user)
                    .then(function (response) {
                        if (response.data === 1) {
                            alert("登录成功");
                            location.href = "/";
                        } else if (response.data === 2) {
                            alert("密码错误");
                        } else {
                            alert("用户名不存在");
                        }
                    })
                    .catch(function (error) {
                        console.error("请求失败:", error);
                        alert("登录失败，请检查网络连接或稍后再试");
                    });
            }
        }
    });
</script>

</body>
</html>
